﻿using Newtonsoft.Json;
using NPOI.SS.UserModel;
using SoftCommon;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAchive.ExContr
{
    internal class JConfig
    {        
        public static ImgClassifyConfig ReadConf()
        {
            ImgClassifyConfig JnClassifyConfig = null;
            try
            {
               
                var cuPath = Environment.CurrentDirectory;
                var filePath = Path.Combine(cuPath, "imgClassfiy.json");
                if (File.Exists(filePath))
                {
                    var allText = File.ReadAllText(filePath);
                    Log.Write("file content:" + allText);
                    if (string.IsNullOrWhiteSpace(allText))
                    {
                        Log.Write("imgClassfiy.json 文件内容为空！");
                    }
                    else
                    {
                        JnClassifyConfig = JsonConvert.DeserializeObject<ImgClassifyConfig>(allText);
                    }
                }
              
            }
            catch (Exception ex)
            {
                SoftCommon.Log.Write(ex);

            }
            return JnClassifyConfig;
        }

        public static void WriteConf(ImgClassifyConfig classifyConfig) 
        {
            try
            {
                var cuPath = Environment.CurrentDirectory;
                var filePath = Path.Combine(cuPath, "imgClassfiy.json");
                File.WriteAllText(filePath, JsonConvert.SerializeObject(classifyConfig));
                Log.Write("写入imgClassfiy end.");
            }
            catch (Exception ex)
            {

                SoftCommon.Log.Write(ex);
            }
          

        }
    }
}
